import { Component, OnInit } from '@angular/core';

import { SheBaoService } from '../../services/shebao.service';
import { SalaryService } from '../../services/salary.service';
import { ISheBao } from '../../commons/shebao';
import { ISalary } from '../../commons/salary';

@Component({
    selector: 'calc-component',
    templateUrl: './calc.component.html',
    styleUrls: ['./calc.component.css']
})
export class CalcComponent implements OnInit {

    public jiBen: number;
    public jiXiao: number;
    public jiangJin: number;

    public showResult: boolean = false;

    public result: ISalary;

    public settings: ISheBao;

    public constructor(
        private sheBaoService: SheBaoService,
        private salaryService: SalaryService
    ) { }

    /**
     * 组件初始化
     * 通过服务获取设置的社保值
     */
    ngOnInit() {
        this.settings = this.sheBaoService.rate;
    }

    /**
     * 计算函数
     * 用于计算各项社保等工资
     */
    public calc() {
        this.jiBen = this.jiBen || 0;
        this.jiXiao = this.jiXiao || 0;
        this.jiangJin = this.jiangJin || 0;
        this.result = this.salaryService.doCalc(this.jiBen, this.jiXiao, this.jiangJin);
        this.showResult = true;
    }
}